<!--邀请开通-->
<template>
<div>
  <div class="m-invite-wrap">
    <div class="m-line-form displayflex">
      <span class="label">所属单位</span>
      <div class="flex1 m-line-form-ipt">
        <input type="text" placeholder="请输入单位名称" v-model="CropName">
      </div>
    </div>
    
    <div class="m-line-form displayflex">
      <span class="label">姓名</span>
      <div class="flex1 m-line-form-ipt">
        <input type="text" placeholder="请输入您的姓名" v-model="Contacts">
      </div>
    </div>

    <div class="m-line-form displayflex">
      <span class="label">手机号</span>
      <div class="flex1 m-line-form-ipt">
        <input type="text" placeholder="请输入您的手机号" v-model="ContactTel">
      </div>
    </div>

    <div class="m-line-form displayflex">
      <span class="label">验证码</span>
      <div class="flex1 m-line-form-ipt">
        <input type="text" placeholder="请填写验证码" v-model="TelCode">
      </div>
      <div class="btn-code" @click="runcode">{{btntext}}</div>
    </div>

    <div class="m-line-form displayflex">
      <span class="label">密码</span>
      <div class="flex1 m-line-form-ipt">
        <input type="password" placeholder="请输入密码" v-model="pwd">
      </div>
    </div>
    <div class="btn-large mt64 mb50" @click="getData">注册</div>
    <div class="logo-img"><img src="~images/logo/login_logo.png"></div>
    <div class="exper">
      您还可以，<a class="link">快速体验</a>
    </div>
  </div>
  <!--二维码 start-->
  <div class="QR_code" v-show="codeshow">
    <a class="iconfont icon-del-black" @click="codeshow = false"></a>
    <div class="imgbox">
      <div id="qr"><img src="~images/bg/ewm.jpg"></div>
      <p class="qr_wz">请识别图中二维码关注恋链</p>
    </div>
  </div>
  <!--二维码 end-->
</div>
</template>

<script>
export default {
  data: function() {
    return {
      id: '',
      btntext: '点击获取',
      second:60,
      clock: '',
      code: '',
      ContactTel: '',
      disabled: true,
      Contacts: '',
      CropName: '',
      pwd: '',
      TelCode: '',
      role: '',
      codeshow:false,
    };
  },
  methods: {
    runcode() {
        var testTel = /^1[345789]\d{9}$/;
        if (!this.ContactTel || !testTel.test(this.ContactTel)) {
            this.Toast({
                message: '请输入正确格式的手机号'
            });
            return false;
        };
        if (!this.disabled) {
            return false;
        };
        var _this = this;
        this.clock = setInterval(_this.sendCode, 1000)

        var Num = "";
        for (var i = 0; i < 4; i++) {
            Num += Math.floor(Math.random() * 10);
        }
        _this.code = Num;
        var Content = '【恋链】 您的验证码是：' + _this.code + '。如非本人操作，请忽略本短信';
        _this.TelCode = _this.code;
        var query={
            ContactTel:this.ContactTel,
            Content:Content,
          };
      // this.Ajax.post('SendMessage',query).then(function (resp){
      //   if (resp.Data.Status != '0') {
      //     this.Toast({
      //         message: '验证码发送失败，请稍后再试！',
      //     });
      //   }else if(resp.IsSuccess && resp.Data.Status == '0'){
      //     this.Toast({
      //         message: '验证码发送成功！',
      //     });
      //   }
      // });
    },
    sendCode: function() {
      var self = this;
      this.second--;
      this.disabled = false;
      this.btntext = this.second + '秒后可重新获取';
      if (this.second == 0) {
        clearInterval(self.clock);
        this.second = 60;
        this.btntext = '点击获取';
        this.disabled = true;
      }
    },
    getData: function() {
      var self = this;
      this.id = this.$route.query.id;
      this.role = this.$route.query.role;
      if (this.CropName == '') {
        this.Toast('请输入您的单位名称！');
        return false;
      }
      if (this.Contacts === '') {
        this.Toast('请输入您的称呼！');
        return false;
      }
      if (this.ContactTel == '') {
        this.Toast('请输入您的手机号码！');
        return false;
      }
      if (this.TelCode=='') {
        this.Toast('请输入您的验证码！');
        return false;
      }
      if (this.code != this.TelCode) {
        this.Toast('输入的验证码不一致！');
        return false;
      }
      if (this.pwd == ''||this.pwd.length<6) {
        this.Toast('请输入至少6位的密码！');
        return false;
      }
      var query = {
        Contacts: this.Contacts,
        ContactTel: this.ContactTel,
        CropName: this.CropName,
        id: this.id,
        Pwd: this.pwd,
        UserType: this.role,
      };
      this.Ajax.post('OpenAccount', query).then(function(resp) {
        if (resp.IsSuccess) {
          self.MessageBox.alert('注册成功！').then(action => {
            self.codeshow = true;
            //jWeixin.closeWindow();
          });
        } else {
          self.Toast({
            message: resp.ErrorMessage || '操作失败，请稍后重试'
          });
        };
      });
    },
  },
  created() {
    document.title = "开通恋链";
  }
};
</script>